package com.hrbxlh.support.attendance.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 考勤状态
 * <p>
 * Created by lx on 2020/5/5.
 */
@Getter
@AllArgsConstructor
public enum AttendanceStateEnum {

    CLOCKED_IN(1, "正常"),
    TRUANT(2, "缺勤");

    private Integer code;

    private String message;

    public static AttendanceStateEnum getByMessage(String message) {
        for (AttendanceStateEnum stateEnum : AttendanceStateEnum.values()) {
            if (Objects.equals(stateEnum.getMessage(), message)) {
                return stateEnum;
            }
        }
        return null;
    }

    public static AttendanceStateEnum getByCode(Integer code) {
        for (AttendanceStateEnum stateEnum : AttendanceStateEnum.values()) {
            if (Objects.equals(stateEnum.getCode(), code)) {
                return stateEnum;
            }
        }
        return null;
    }

    public static String getMessageByCode(Integer code) {
        AttendanceStateEnum stateEnum = getByCode(code);
        return stateEnum == null ? null : stateEnum.getMessage();
    }

}
